#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int s[110],t;
int m,n,k,p;
int father[330];
int next[330];
int inf=0xffffff;
struct arc
{
	int link;
	int flow;
	int cost;
	int rp;
	arc(int l,int f,int co,int r)
	{
		link=l,flow=f,cost=co,rp=r;
	}
};
vector<arc> a[330];
int SPFA(int vs,int vt)
{
	int w[330],from,i,t;
	bool done[330];
	queue<int> mq;
	fill(w,w+330,inf);
	fill(done,done+330,false);
	mq.push(vs);
	w[vs]=0;
	while(!mq.empty())
	{
		from=mq.front();
		mq.pop();
		done[from]=0;
		for(i=0;i<a[from].size();i++)
		{
			t=a[from][i].link;
			if(a[from][i].flow&&a[from][i].cost+w[from]<w[t])
			{
				w[t]=a[from][i].cost+w[from];
				father[t]=from;
				next[t]=i;
				if(!done[t])
				{
					mq.push(t);
					done[t]=1;
				}
			}
		}
	}
    return w[vt];
}
int f(int vs,int vt)
{
    int t,sum=0,i,j;
    while(1)
    {
        //fill(father,father+330,-1);
        t=SPFA(vs,vt);
     //   cout<<t<<endl;
        if(t==inf) break;
        for(i=vt;i!=vs;i=father[i])
        {
            j=a[father[i]][next[i]].rp;
			a[father[i]][next[i]].flow--;
            a[i][j].flow++;
  /*          if((i>m&&i<=m+n)||(father[i]>m&&father[i]<=m+n))
            {
                a[i][j].cost-=a[father[i]][next[i]].cost;
                a[father[i]][next[i]].cost-=a[father[i]][next[i]].cost;
            }*/
        }
        sum+=t;
    }
    return sum;
}
void add(int v1,int v2,int flow,int cost)
{
    a[v1].push_back(arc(v2,flow,cost,a[v2].size()));
    a[v2].push_back(arc(v1,flow,cost,a[v1].size()-1));
}
int main()
{
    int i,j,from,to,cost,sum;
    while(cin>>n>>m>>k>>p)
    {
        sum=0;
        for(i=0;i<330;i++)a[i].clear();
        for(i=1;i<=n;i++)
        {
            scanf("%d",&s[i]);
        }
        for(i=0;i<k;i++)
        {
            scanf("%d%d%d",&from,&to,&cost);
            add(from,to,inf,cost);
        }
        for(i=0;i<p;i++)
        {
            scanf("%d%d%d",&from,&to,&cost);
            from+=m;
            add(to,from,1,cost);
            a[from].back().flow=0;
            a[from].back().cost=-cost;
        }
        for(i=1;i<=n;i++)
        {
            add(0,s[i],1,0);
            a[s[i]].back().flow=0;
            add(m+i,m+n+1,1,0);
            a[m+n+1].back().flow=0;
        }
        cout<<f(0,m+n+1)<<endl;
    }
    return 0;
}

